﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using BrokerBase.Lib.Policy;

namespace Broker.View.Converter
{
    public class PeriodLengthConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string result = null;

            string par=parameter.ToString();

            IPolicy policy = value as IPolicy;

            if (policy != null)
            {
                if (par == "Pay")
                {
                    if (policy.OverPaymentPeriod > 1)
                        result = policy.PaymentPeriodLength + "年期";
                    else
                        result = policy.SelectedPaymentPeriod.Name;

                }
                else if (par == "Ins")
                {
                    if (policy.OverInsurancePeriod > 1)
                        result = policy.InsurancePeriodLength + "年期";
                    else
                        result = policy.SelectedInsurancePeriod.Name;
                }

            }

            return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
